import {Component} from '@angular/core';
import {AlertController,App, LoadingController, NavController, Platform, ToastController} from 'ionic-angular';
import {BasePage} from "../../BasePage";
import {UserManager} from "../../../framework/manager/UserManager";
import {LoginPage} from "../../login/login";
import {SystemService} from "../../service/SystemService";
import {log} from "util";
import {Log} from "../../../framework/utils/Log";
import {SLLocalStorageUtils} from "../../../framework/utils/SLLocalStorageUtils";

@Component({
    selector: 'resetpassword-my',
    templateUrl: 'reset-password.html',
    providers:[SystemService]
})
export class ResetPasswordPage extends BasePage {

    pwdInfo?:any = {
        YongHuBH: '',
        MiMa: '',
        YuanMiM: ''
    };
    repwd: string;
    private _userId:string;
    constructor(public navCtrl: NavController,
                public sys:SystemService,
                public platform: Platform,
                public loadingCtrl: LoadingController,
                public toastCtrl: ToastController,
                public alertCtrl: AlertController,public app: App) {
        super(platform, loadingCtrl, toastCtrl, alertCtrl);
        this._userId = UserManager.getInstance().user.userId;
        this.pwdInfo.YongHuBH=this._userId;
    }
    ionViewDidLoad() {
        Log.w('Tag','ResetPasswordPage');
    }
    updatePwd(){

        if(this.pwdInfo.YuanMiM ==""){
            this.showError('请输入正确的原密码');
            return;
        } else if(this.pwdInfo.MiMa =="" || this.repwd ==""){
            this.showError('请输入新密码');
            return;
        }else if(this.pwdInfo.MiMa !=this.repwd ){
            this.showError('输入的新密码不一致');
            return;
        }else {
            this.sys.getUpdatePwd(this.pwdInfo).subscribe((res:any)=>{
                if(res.msgCode =="1"){
                    this.showToast("密码修改成功");
                    //this.navCtrl.pop();
                    this.app.getRootNav().setRoot(LoginPage);
                    //this.navCtrl.setRoot(LoginPage);
                    SLLocalStorageUtils.getInstance().destroy();
                }else {
                    this.showToast("密码修改失败");
                }
            },error=>{
                this.showToast("密码修改失败");
            })
        }
    }
}
